﻿using System;
using Super_Management_Mayhem.Content.Spritesheet.Player;
using Transformable_Engine_v2.Engine.Animation.FrameAnimation;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Time;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Players.Manager
{
    public partial class Manager
    {
        private Timer _throwTimer;

        private void InitializeThrowStateObjects()
        {
            _throwTimer = new Timer(200, false, EndThrow);
            AddTimers(_throwTimer);
        }

        private void EndThrow()
        {
            ChangeState(PlayerState.Idle);
        }

        private void HandleKeyPressThrowState(Input input)
        {
        }

        private void HandleKeyReleaseThrowState(Input input) {}

        private void InitializeThrowState()
        {
            _pickUpItem.Throw(_player.Position, _pickUpItemLayer.AbsolutePosition, _latestDirection, _statistics.GetTeam());
            
            DestroyCarriedObject();
            switch(_latestDirection)
            {
                case Direction.Up:
                    _character.Sprite = ManagerSheet.GetSprite(ManagerSheet.ThrowState.Up);
                    _character.OriginAbsolute = new TE_Vector2(8, 28);
                    break;
                case Direction.Down:
                    _character.Sprite = ManagerSheet.GetSprite(ManagerSheet.ThrowState.Down);
                    _character.OriginAbsolute = new TE_Vector2(8, 34);
                    break;
                case Direction.Left:
                    _character.Sprite = ManagerSheet.GetSprite(ManagerSheet.ThrowState.Left);
                    _character.OriginAbsolute = new TE_Vector2(12, 31);
                    break;
                case Direction.Right:
                    _character.Sprite = ManagerSheet.GetSprite(ManagerSheet.ThrowState.Right);
                    _character.OriginAbsolute = new TE_Vector2(11, 31);
                    break;
            }

            _throwTimer.Start();
        }

        void DestroyCarriedObject()
        {
            _isCarrying = false;
            ((Container)_pickUpItem).Die();
        }

        private void UpdateThrowState(TimeSpan gameTime)
        {
        }
    }
}